<?php
namespace Hong\Webdav;

trait TraitPut
{
    /**
	 * 上传本地文件到WebDAV服务器 (PUT)
	 * @param string $remotePath 远程路径
	 * @param string $localPath 本地文件路径
	 * @param array $headers header自定义头
	 * @return bool 是否成功
	 * @throws \RuntimeException 当上传失败或本地文件不存在时抛出异常
	 */
	public function put($remotePath, $localPath, $headers = [])
	{
		if (!file_exists($localPath)) {
			throw new \RuntimeException("Local file not found: " . $localPath);
			return false;
		}

		$response = $this->sendRequest('PUT', $remotePath, $localPath, $headers);

		if ($response['status'] >= 200 && $response['status'] < 300) {
			return true;
		}

		throw new \RuntimeException("Failed to PUT file. Server responded with status: " . $response['status']);
		return false;
	}
}